# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=mdbook-admonish
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.19.0
pkgrel=1
pkgdesc='A preprocessor for mdbook to add Material Design admonishments (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://tommilligan.github.io/mdbook-admonish'
msys2_repository_url='https://github.com/tommilligan/mdbook-admonish'
msys2_references=(
  'aur: mdbook-admonish'
  'purl: pkg:cargo/mdbook-admonish'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-mdbook")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("${msys2_repository_url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('88f821c8eef74868181acaacfeab311c9d160986a8e688bd63c9a437d2328758')

prepare() {
  cp -r "${_realname}-${pkgver}" "build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${srcdir}/build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" build \
    --release \
    --frozen
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  "${MINGW_PREFIX}/bin/cargo.exe" test \
    --release \
    --frozen
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  install -Dm755 "target/release/${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
  install -Dm644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
